<template>
	<view>
		<u-navbar height="50" back-icon-color="#333" title="提现" title-color="#333" title-size="36"></u-navbar>
		<!-- <view class="bankCard">
			<view class="left">
				<view class="card">
					<image src="/static/图层 32.png" mode="widthFix" style="width: 64rpx; height: 64rpx;"></image>
				</view>
				<view class="ct">
					<view class="title">
						银行卡
					</view>
					<view class="ipt">
						<span v-if="false" style="color: #999999FF;">已绑定</span><input type="text" disabled placeholder="请添加到账银行卡" v-model="bank_account" />
					</view>
				</view>
			</view>
			<view class="right" @click="onShowBank()">
				<span>去绑定</span><span v-if="false">更换绑定</span>
			</view>
		</view> -->
		<view class="content">

			<view class="content-name">提现金额</view>
			<view class="content-input">
				<text class="left-name">￥</text>
				<input type="text" placeholder="请输入提现金额" v-model="post_amount">
			</view>
			<view class="content-input">
				<input type="number" placeholder="请输入卡号" v-model="card_no">
			</view>
			<view class="content-input">
				<input type="text" placeholder="请输入开户行" v-model="card_name">
			</view>
			<view class="content-amount">
				<text>当前可提现余额￥{{earnings}}，</text>
				<text @click="onAllPost()">全部提现</text>
			</view>

		</view>
		<view class="content-btn">
			<button @click="onSubmit()">申请提现</button>
		</view>
		<view class="tips">
			<text>温馨提示</text>
			<view class="smallTip">1、提现手续费0.06%；</view>
			<view class="smallTip">2、提现时间：9:00~18:00 周一至周六</view>
			<view class="smallTip">3、到账时间72小时内</view>
		</view>
		<u-popup ref="dialog" mode="center" border-radius="20">
			<view class="popupView">
				<!-- <image src="/static/success.png" mode="aspectFit"></image> -->
				<text class="popup-text1">提现申请成功</text>
				<text class="popup-text2">系统将在1-3个工作日内审核完成并打款提现金额到制定账号</text>
				<button @click="onClose()">知道了</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {getteamtotal,getcashapply} from '@/api/user.js'
	import { toast } from '../../utils/common';
	export default {
		data() {
			return {
				earnings: '0.00',
				bank_id: '',
				bank_account: '',
				post_amount: '',
				card_no:"",
				card_name:""
		
			}
		},
		onLoad() {
			this.initData();
		},
		// A页面接收参数：
		onShow(object){
		    console.log(object)
		},
		methods: {
			onClose() {
				uni.navigateBack({
					delta: 1
				});
			},
			// 去绑定
			onShowBank() {
				uni.navigateTo({
					url:'/other/my-card/my-card'
				})
			},
			initData(){
				getteamtotal().then(res=>{
					console.log("余额",res);
					this.earnings = res.data.income
				})
			},
			// 全部提现
			onAllPost() {
				this.post_amount = this.earnings;
			},
			// 开始提现
			onSubmit() {
				let self = this;
				if (!this.post_amount) {
					toast('请输入提现金额');
					return
				}
				if (!this.card_no) {
					toast('请输入银行卡号');
					return
				}
				if (!this.card_no) {
					toast('请输入开户行');
					return
				}
				if(this.post_amount>this.earnings){
					toast("不能超过余额")
					return
				}
				if(this.post_amount==0){
					toast("不能提现0元")
					return
				}
				getcashapply({
					cash_pay_account: this.card_no,
					cash_pay_bank: this.card_name,
					cash_amount:this.post_amount
				}).then(res => {
					if(res.data==1){
						toast('提现成功');
						setTimeout(function() {
							self.$refs.dialog.open();
						}, 500);
						
					}else{
						toast(res.data.msg)
					}
					
				});
			},
		}
	}
</script>

<style>
	@import url('withdrawal.css');

	page {
		background: #f5f5f5;
	}
</style>